#pragma once
#include "GEnginePCH.h"



#define SCREEN_WIDTH 1366
#define SCREEN_HEIGHT 768

//-----------------------------------------------------------------------------
// MACROS
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }

const float EPSILON  = 0.001f;

extern IDirect3DDevice9* d3ddev;


struct VERTEX
{
	float x, y, z;
	float tu, tv;
};
struct COLORED_VERTEX
{
	float x, y, z;
	D3DCOLOR color;
};
struct POSITION_VERTEX
{
	float x, y, z;
};

const D3DXCOLOR WHITE(1.0f, 1.0f, 1.0f, 1.0f);
const D3DXCOLOR BLACK(0.0f, 0.0f, 0.0f, 1.0f);
const D3DXCOLOR RED(1.0f, 0.0f, 0.0f, 1.0f);
const D3DXCOLOR GREEN(0.0f, 1.0f, 0.0f, 1.0f);
const D3DXCOLOR BLUE(0.0f, 0.0f, 1.0f, 1.0f);

struct Mtrl
{
	Mtrl()
		:ambient(WHITE), diffuse(WHITE), spec(WHITE), specPower(8.0f){}
	Mtrl(const D3DXCOLOR& a, const D3DXCOLOR& d, 
		const D3DXCOLOR& s, float power)
		:ambient(a), diffuse(d), spec(s), specPower(power){}

	D3DXCOLOR ambient;
	D3DXCOLOR diffuse;
	D3DXCOLOR spec;
	float specPower;
};

struct DirLight
{
	D3DXCOLOR ambient;
	D3DXCOLOR diffuse;
	D3DXCOLOR spec;
	D3DXVECTOR3 dirW;
};

	
class Entity;

void ScaleAndTranslateAndRotate( D3DXMATRIX &world, const D3DXMATRIX& matVP, float ix,float ygrec,float zet,float angleX,float angleY,float angleZ,float six,float sygrec,float szet);
void ScaleAndTranslateAndRotate( D3DXMATRIX &world, const D3DXMATRIX& matVP, const D3DXVECTOR3& vPos, const D3DXVECTOR3& vRot, const D3DXVECTOR3& vScale);
void ScaleAndTranslateAndRotate( D3DXMATRIX &world, const D3DXMATRIX& matVP, Entity* entity);
void CalcWorld( D3DXMATRIX &world, float ix, float ygrec, float zet, float angleX, float angleY, float angleZ, float six, float sygrec, float szet);
void CalcWorld(D3DXMATRIX &world, const D3DXVECTOR3& vPos, const D3DXVECTOR3& vRot, const D3DXVECTOR3& vScale);
void SetShaderConst( const D3DXMATRIX& world, const D3DXMATRIX& matVP);



inline float DistRayPlane(D3DXVECTOR3& rayOrigin,
                          D3DXVECTOR3& rayVector,
                          D3DXVECTOR3& planeNormal,
                          float planeD);
bool DoesRayIntersectTriangle( const D3DXVECTOR3& orig,
                               const D3DXVECTOR3& dir, D3DXVECTOR3& v0,
                               D3DXVECTOR3& v1, D3DXVECTOR3& v2,
                               float& t, float& u, float& v );

void GetRay( int x, int y, D3DXVECTOR3 &vRayOrig, D3DXVECTOR3 &vRayDir,const D3DXMATRIX &matView,const D3DXMATRIX &matProj);

void printVector(const D3DXVECTOR3 &vect);
void printMatrix(const D3DXMATRIX &matrix);
int RandomInt(int iMin, int iMax);
float RandomFloat(float fMin, float fMax);
D3DXVECTOR3 RandomVector(D3DXVECTOR3 vMin, D3DXVECTOR3 vMax);
inline DWORD FtoDW( FLOAT f ) { return *((DWORD*)&f); }
void MessBox(char *debugStr);
float DistanceSquared2D (const D3DXVECTOR3 &a, const D3DXVECTOR3 &b);